package cn.cs.service.impl;

import cn.cs.client.SetPolicyClient;
import cn.cs.common.Constants;
import cn.cs.common.EmptyUtils;
import cn.cs.common.Page;
import cn.cs.pojo.SetPolicy;
import cn.cs.service.SetPolicyService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class SetPolicyServiceImpl implements SetPolicyService {

    @Resource
    private SetPolicyClient setPolicyClient;

    public SetPolicy getSetPolicyById(String id) throws Exception {
        return setPolicyClient.getSetPolicyById(id);
    }

    public List<SetPolicy> getSetPolicyListByMap(Map<String, Object> param) throws Exception {
        return setPolicyClient.getSetPolicyListByMap(param);
    }

    public Integer getSetPolicyCountByMap(Map<String, Object> param) throws Exception {
        return setPolicyClient.getSetPolicyCountByMap(param);
    }

    public Integer addSetPolicy(SetPolicy setPolicy) throws Exception {
        return setPolicyClient.addSetPolicy(setPolicy);
    }

    public Integer modifySetPolicy(SetPolicy setPolicy) throws Exception {
        return setPolicyClient.modifySetPolicy(setPolicy);
    }

    public Integer deleteSetPolicyById(Long id) throws Exception {
        return setPolicyClient.deleteSetPolicyById(id);
    }

    public Page<SetPolicy> querySetPolicyPageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) throws Exception {
        Integer total = setPolicyClient.getSetPolicyCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<SetPolicy> setPolicyList = setPolicyClient.getSetPolicyListByMap(param);
        page.setRows(setPolicyList);
        return page;
    }

}
